import { STAGE_CI } from '../../../../stores/CONSTANTS';

export default (sourceData: any):any => ({
  dataToJson: false,
  autoQuery: false,
  forceValidate: true,
  fields: [
    {
      name: 'name',
      maxLength: 30,
      type: 'string',
      label: '阶段名称',
      required: true,
      defaultValue: STAGE_CI,
      validator: (value: string) => {
        if (sourceData) {
          const existNames = sourceData.map((i: any) => i.name);
          if (existNames.includes(value)) {
            return '阶段名称不能重复';
          }
          return true;
        }
        return true;
      },
    },
    {
      name: 'type', type: 'string', label: '阶段属性', required: false,
    },
  ],
});
